////////////////////////////////////////////////////////////////////////////
//
//  Immense Engine Source File.
//  Copyright (C), Indloon 2012
// -------------------------------------------------------------------------
//  File name:   ieMathColor.cpp
//  Description: A color class functions
//  Created:     8/12/2012 Genert Org
//  Compilers:   Visual C++ 2010 Express
// -------------------------------------------------------------------------
//  History:
//
////////////////////////////////////////////////////////////////////////////
#include "ieCommon.h"

ieVec4		ColorBlack			= ieVec4( 0.00f, 0.00f, 0.00f, 1.00f );
ieVec4		ColorRed			= ieVec4( 1.00f, 0.00f, 0.00f, 1.00f );
ieVec4		ColorGreen			= ieVec4( 0.00f, 1.00f, 0.00f, 1.00f );
ieVec4		ColorBlue			= ieVec4( 0.00f, 0.00f, 1.00f, 1.00f );
ieVec4		ColorYellow			= ieVec4( 1.00f, 1.00f, 0.00f, 1.00f );
ieVec4		ColorCyan			= ieVec4( 0.00f, 1.00f, 1.00f, 1.00f );
ieVec4		ColorMagenta		= ieVec4( 1.00f, 0.00f, 1.00f, 1.00f );
ieVec4		ColorWhite			= ieVec4( 1.00f, 1.00f, 1.00f, 1.00f );
ieVec4		ColorOrange			= ieVec4( 1.00f, 0.50f, 0.00f, 1.00f );
ieVec4		ColorChartreuse		= ieVec4( 0.50f, 1.00f, 0.00f, 1.00f );
ieVec4		ColorSpringGreen	= ieVec4( 0.00f, 1.00f, 0.50f, 1.00f );
ieVec4		ColorAzure			= ieVec4( 0.00f, 0.50f, 1.00f, 1.00f );
ieVec4		ColorViolet			= ieVec4( 0.50f, 0.00f, 1.00f, 1.00f );
ieVec4		ColorRose			= ieVec4( 1.00f, 0.00f, 0.50f, 1.00f );
ieVec4		ColorGray			= ieVec4( 0.50f, 0.50f, 0.50f, 1.00f );

ieVec4 Color_table[64] = {
	ieVec4( 0.00f, 0.00f, 0.00f, 1.00f ),		//  0 = Black
	ieVec4( 1.00f, 0.00f, 0.00f, 1.00f ),		//  1 = Red
	ieVec4( 0.00f, 1.00f, 0.00f, 1.00f ),		//  2 = Green
	ieVec4( 0.00f, 0.00f, 1.00f, 1.00f ),		//  3 = Blue
	ieVec4( 1.00f, 1.00f, 0.00f, 1.00f ),		//  4 = Yellow
	ieVec4( 0.00f, 1.00f, 1.00f, 1.00f ),		//  5 = Cyan
	ieVec4( 1.00f, 0.00f, 1.00f, 1.00f ),		//  6 = Magenta
	ieVec4( 1.00f, 1.00f, 1.00f, 1.00f ),		//  7 = White
	ieVec4( 1.00f, 0.75f, 0.00f, 1.00f ),		//  8 = Amber
	ieVec4( 0.55f, 0.71f, 0.00f, 1.00f ),		//  9 = Apple green
	ieVec4( 0.18f, 0.55f, 0.34f, 1.00f ),		// 10 = Aquamarine
	ieVec4( 0.65f, 0.16f, 0.16f, 1.00f ),		// 11 = Auburn
	ieVec4( 0.00f, 0.50f, 1.00f, 1.00f ),		// 12 = Azure
	ieVec4( 0.96f, 0.96f, 0.86f, 1.00f ),		// 13 = Beige
	ieVec4( 0.59f, 0.29f, 0.00f, 1.00f ),		// 14 = Brown
	ieVec4( 0.65f, 0.48f, 0.36f, 1.00f ),		// 15 = Café au lait
	ieVec4( 0.00f, 0.75f, 1.00f, 1.00f ),		// 16 = Capri
	ieVec4( 0.70f, 1.00f, 1.00f, 1.00f ),		// 17 = Celeste
	ieVec4( 0.50f, 1.00f, 0.00f, 1.00f ),		// 18 = Chartreuse
	ieVec4( 0.48f, 0.25f, 0.00f, 1.00f ),		// 19 = Chocolate
	ieVec4( 1.00f, 0.50f, 0.31f, 1.00f ),		// 20 = Coral
	ieVec4( 0.39f, 0.58f, 0.93f, 1.00f ),		// 21 = Cornflower blue
	ieVec4( 1.00f, 0.99f, 0.82f, 1.00f ),		// 22 = Cream
	ieVec4( 0.86f, 0.08f, 0.24f, 1.00f ),		// 23 = Crimson
	ieVec4( 0.00f, 0.50f, 0.00f, 1.00f ),		// 24 = Dark green
	ieVec4( 0.31f, 0.78f, 0.47f, 1.00f ),		// 25 = Emerald
	ieVec4( 0.96f, 0.00f, 0.63f, 1.00f ),		// 26 = Fuchsia
	ieVec4( 0.69f, 0.40f, 0.00f, 1.00f ),		// 27 = Ginger
	ieVec4( 1.00f, 0.84f, 0.00f, 1.00f ),		// 28 = Golden
	ieVec4( 0.85f, 0.65f, 0.13f, 1.00f ),		// 29 = Goldenrod
	ieVec4( 0.50f, 0.50f, 0.50f, 1.00f ),		// 30 = Gray
	ieVec4( 0.29f, 0.00f, 1.00f, 1.00f ),		// 31 = Indigo
	ieVec4( 0.00f, 0.66f, 0.42f, 1.00f ),		// 32 = Jade
	ieVec4( 0.76f, 0.69f, 0.57f, 1.00f ),		// 33 = Khaki
	ieVec4( 0.71f, 0.49f, 0.86f, 1.00f ),		// 34 = Lavender
	ieVec4( 0.68f, 0.85f, 0.90f, 1.00f ),		// 35 = Light blue
	ieVec4( 0.78f, 0.64f, 0.78f, 1.00f ),		// 36 = Lilac
	ieVec4( 0.75f, 1.00f, 0.00f, 1.00f ),		// 37 = Lime
	ieVec4( 0.50f, 0.00f, 0.00f, 1.00f ),		// 38 = Maroon
	ieVec4( 0.00f, 0.00f, 0.50f, 1.00f ),		// 39 = Navy blue
	ieVec4( 0.80f, 0.47f, 0.13f, 1.00f ),		// 40 = Ochre
	ieVec4( 0.50f, 0.50f, 0.00f, 1.00f ),		// 41 = Olive
	ieVec4( 1.00f, 0.50f, 0.00f, 1.00f ),		// 42 = Orange
	ieVec4( 0.85f, 0.44f, 0.84f, 1.00f ),		// 43 = Orchid
	ieVec4( 1.00f, 0.75f, 0.80f, 1.00f ),		// 44 = Pink
	ieVec4( 0.50f, 0.00f, 0.50f, 1.00f ),		// 45 = Purple
	ieVec4( 1.00f, 0.00f, 0.50f, 1.00f ),		// 46 = Rose
	ieVec4( 1.00f, 0.55f, 0.41f, 1.00f ),		// 47 = Salmon
	ieVec4( 0.06f, 0.32f, 0.73f, 1.00f ),		// 48 = Sapphire
	ieVec4( 1.00f, 0.14f, 0.00f, 1.00f ),		// 49 = Scarlet
	ieVec4( 0.44f, 0.26f, 0.08f, 1.00f ),		// 50 = Sepia
	ieVec4( 0.53f, 0.18f, 0.09f, 1.00f ),		// 51 = Sienna
	ieVec4( 0.75f, 0.75f, 0.75f, 1.00f ),		// 52 = Silver
	ieVec4( 0.44f, 0.50f, 0.56f, 1.00f ),		// 53 = Slate gray
	ieVec4( 0.00f, 1.00f, 0.50f, 1.00f ),		// 54 = Spring green
	ieVec4( 0.27f, 0.51f, 0.71f, 1.00f ),		// 55 = Steel blue
	ieVec4( 0.82f, 0.71f, 0.55f, 1.00f ),		// 56 = Tan
	ieVec4( 0.00f, 0.50f, 0.50f, 1.00f ),		// 57 = Teal
	ieVec4( 0.89f, 0.45f, 0.36f, 1.00f ),		// 58 = Terracotta
	ieVec4( 0.19f, 0.84f, 0.78f, 1.00f ),		// 59 = Turquoise
	ieVec4( 0.95f, 0.90f, 0.67f, 1.00f ),		// 60 = Vanilla
	ieVec4( 0.89f, 0.26f, 0.20f, 1.00f ),		// 61 = Vermilion
	ieVec4( 0.50f, 0.00f, 1.00f, 1.00f ),		// 62 = Violet
	ieVec4( 0.45f, 0.18f, 0.22f, 1.00f )		// 63 = Wine
};

// -------------------------------------------------------------------------------------------------------------
void ieColor::Pack( const float l )
{
	this->r = ieMath::FloatToByte( l * 255.0f );
	this->g = ieMath::FloatToByte( l * 255.0f );
	this->b = ieMath::FloatToByte( l * 255.0f ) ;
	this->a = 255;
}
// -------------------------------------------------------------------------------------------------------------
void ieColor::Pack( const float l, const float a )
{
	this->r = ieMath::FloatToByte( l * 255.0f );
	this->g = ieMath::FloatToByte( l * 255.0f );
	this->b = ieMath::FloatToByte( l * 255.0f ) ;
	this->a = ieMath::FloatToByte( a * 255.0f );
}
// -------------------------------------------------------------------------------------------------------------
void ieColor::Pack( const float r, const float g, const float b )
{
	this->r = ieMath::FloatToByte( r * 255.0f );
	this->g = ieMath::FloatToByte( g * 255.0f );
	this->b = ieMath::FloatToByte( b * 255.0f );
	this->a = 255;
}
// -------------------------------------------------------------------------------------------------------------
void ieColor::Pack( const float r, const float g, const float b, const float a )
{
	this->r = ieMath::FloatToByte( r * 255.0f );
	this->g = ieMath::FloatToByte( g * 255.0f );
	this->b = ieMath::FloatToByte( b * 255.0f );
	this->a = ieMath::FloatToByte( a * 255.0f );
}
// -------------------------------------------------------------------------------------------------------------
void ieColor::Pack( const ieVec3 &rgb )
{
	r = ieMath::FloatToByte( rgb[0] * 255.0f );
	g = ieMath::FloatToByte( rgb[1] * 255.0f );
	b = ieMath::FloatToByte( rgb[2] * 255.0f );
	a = 255;
}
// -------------------------------------------------------------------------------------------------------------
void ieColor::Pack ( const ieVec4 &rgba )
{
	r = ieMath::FloatToByte( rgba[0] * 255.0f );
	g = ieMath::FloatToByte( rgba[1] * 255.0f );
	b = ieMath::FloatToByte( rgba[2] * 255.0f );
	a = ieMath::FloatToByte( rgba[3] * 255.0f );
}
// -------------------------------------------------------------------------------------------------------------
void ieColor::Unpack ( float &l ) const 
{
	l = ( ( this->r * 0.2125f ) + ( this->g * 0.7154f ) + ( this->b * 0.0721f ) ) * ( 1.0f / 255.0f );
}
// -------------------------------------------------------------------------------------------------------------
void ieColor::Unpack ( float &l, float &a ) const 
{
	l = ( ( this->r * 0.2125f ) + ( this->g * 0.7154f ) + ( this->b * 0.0721f ) ) * ( 1.0f / 255.0f );
	a = this->a * ( 1.0f / 255.0f );
}
// -------------------------------------------------------------------------------------------------------------
void ieColor::Unpack( float &r, float &g, float &b ) const 
{
	r = this->r * ( 1.0f / 255.0f );
	g = this->g * ( 1.0f / 255.0f );
	b = this->b * ( 1.0f / 255.0f );
}
// -------------------------------------------------------------------------------------------------------------
void ieColor::Unpack( float &r, float &g, float &b, float &a ) const
{
	r = this->r * ( 1.0f / 255.0f );
	g = this->g * ( 1.0f / 255.0f );
	b = this->b * ( 1.0f / 255.0f );
	a = this->a * ( 1.0f / 255.0f );
}
// -------------------------------------------------------------------------------------------------------------
void ieColor::Unpack( ieVec3 &rgb ) const 
{
	rgb[0] = r * ( 1.0f / 255.0f );
	rgb[1] = g * ( 1.0f / 255.0f );
	rgb[2] = b * ( 1.0f / 255.0f );
}
// -------------------------------------------------------------------------------------------------------------
void ieColor::Unpack( ieVec4 &rgba ) const 
{
	rgba[0] = r * ( 1.0f / 255.0f );
	rgba[1] = g * ( 1.0f / 255.0f );
	rgba[2] = b * ( 1.0f / 255.0f );
	rgba[3] = a * ( 1.0f / 255.0f );
}
// -------------------------------------------------------------------------------------------------------------